"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025/6/24
"""
import requests
from time import sleep
from lxml import etree
dir_name = 'jianliLib'

headers = {
    'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36',
}
for page in range(1,3):
    if page == 1:
        main_url = 'https://sc.chinaz.com/jianli/free.html'
    else:
        main_url = 'https://sc.chinaz.com/jianli/free_%d.html'%page

    response = requests.get(url=main_url,headers=headers)
    response.encoding = 'utf-8'
    page_text = response.text
    tree = etree.HTML(page_text)
    div_list = tree.xpath('//*[@id="container"]/div')
    for div in div_list:
        sleep(0.5)
        detail_url = div.xpath('./p/a/@href')[0]
        title =  div.xpath('./p/a/text()')[0]

        detail_page_text = requests.get(detail_url,headers=headers).text
        tree = etree.HTML(detail_page_text)
        #解析到了简历的下载链接
        down_load_url = tree.xpath('//*[@id="down"]/div[2]/ul/li[1]/a/@href')[0]
        data = requests.get(down_load_url,headers=headers).content
        with open('jianliLib/'+title+'.rar','wb') as fp:
            fp.write(data)
            print(title,'保存下载成功！')